﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using MySql.Data;
using MySql.Data.MySqlClient;
using System.Data;

namespace WordList
{
    class Program
    {
        static void Main(string[] args)
        {
            UpdateTable();
            User user = new User();
            UserService.CreateWordList(user);
            UserService.CreateWordList(user);
            List<Word> words = UserService.GetWordList(user);
            if (user.List.Count == 0) Console.WriteLine("a");
            else if (words.Count==0) Console.WriteLine("b");
            else
            {
                foreach(Word wd in words)
                {
                    Console.WriteLine(wd.Id + " " + wd.Text + " " + wd.Proficiency + " " + wd.Times); ;
                }
            }
            while (true)
            {
                Console.WriteLine("请输入操作序号:(1:背单词 2:复习 3:退出)");
                int s = Convert.ToInt32(Console.ReadLine());
                if (s == 1) WordService.Recite(words);
                else if (s == 2) WordService.Review(words);
                else if (s == 3) break;
                else Console.WriteLine("无效字符!");
            }
        }
        private static void UpdateTable()
        {
            using(MySqlConnection conn = UserService.GetConnection())
            {
                string sql = "select * from CET6";
                using(MySqlDataAdapter dataAdapter=new MySqlDataAdapter(sql, conn))
                {
                    MySqlCommandBuilder cmdBuilder = new MySqlCommandBuilder(dataAdapter);
                    using(DataSet ds=new DataSet())
                    {
                        dataAdapter.Fill(ds);
                        DataRow newRow = ds.Tables[0].NewRow();
                        newRow[0] = 17;
                        newRow[1] = "adjustable";
                        newRow[2] = 1;
                        newRow[3] = 1;
                        ds.Tables[0].Rows.Add(newRow);
                        dataAdapter.Update(ds);
                    }
                }
            }
        }
    }
}
